package abg.core.common.util;

import com.alibaba.fastjson2.JSONObject;

public class ObjectKit {
    public static boolean isBlank(Object cs) {
        if (cs == null) {
            return true;
        }
        if (cs instanceof String) {
            return StringKit.isBlank(cs.toString());
        }
        return false;
    }

    public static boolean isNotBlank(Object cs) {
        return !isBlank(cs);
    }

    public static JSONObject copyToJSON(Object origin, String... keys) {
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(origin));
        JSONObject newJSONObject = new JSONObject();
        for (String key : keys) {
            newJSONObject.put(key, jsonObject.get(key));
        }
        return newJSONObject;

    }

    public static <T> T copyToNew(T origin, String... keys) {
        JSONObject jsonObject1 = copyToJSON(origin, keys);
        return (T) JSONObject.parseObject(jsonObject1.toString(), origin.getClass());
    }


    public static <T> T copyTo(Object from, T to, String... keys) {
        JSONObject fromJ = JSONObject.parseObject(JSONObject.toJSONString(from));
        JSONObject toJ = JSONObject.parseObject(JSONObject.toJSONString(to));
        for (String key : keys) {
            toJ.put(key, fromJ.get(key));
        }
        return (T) JSONObject.parseObject(toJ.toString(), to.getClass());
    }

}
